import time

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


# 创建浏览器对象
browser = webdriver.Chrome()

# 创建等待对象
wait_ob = WebDriverWait(browser,10)

# 打开用以邮箱
browser.get('https://mail.163.com/')

time.sleep(3)
# dologin = wait_ob.until(EC.presence_of_element_located((By.ID, 'dologin')))

# 定位iframe
iframe = browser.find_element_by_xpath('//iframe')
# iframe=browser.find_element_by_id("x-URS-iframe1605236251358.7385")
print('---------------------------选定iframe')
browser.switch_to.frame(iframe)
browser.find_element_by_xpath('//input[@name="email"][@placeholder="邮箱帐号或手机号码"]').send_keys('luozhiyuanlo')
print('------------------------账号已经输入')
browser.find_element_by_xpath('//input[@name="password"][@placeholder="输入密码"]').send_keys('wslzyok..')
print('------------------------密码已输入')
browser.find_element_by_xpath('//a[@id="dologin"]').click()
# dologin.click()
print('------------------------点击登录')
time.sleep(3)

# browser.close()
browser.find_element_by_xpath('//li[@id="_mail_component_132_132"]').click()

time.sleep(3)
browser.find_element_by_xpath('//input[@aria-label="收件人地址输入框，请输入邮件地址，多人时地址请以分号隔开"]').send_keys('dong4716138_10@163.com')
print('----------------------------输入收件人邮箱')
# time.sleep(3)
browser.find_element_by_xpath('//div[@aria-label="邮件主题输入框，请输入邮件主题"]/input[@type="text"]').send_keys('发送邮件')

iframe = browser.find_element_by_xpath('//iframe[@style="position:absolute"]')

# iframe=browser.find_element_by_id("x-URS-iframe1605236251358.7385")
print('---------------------------选定iframe')
browser.switch_to.frame(iframe)
# dong4716138_10@163.com;

browser.find_element_by_xpath('//body/p').send_keys('罗志远')
print('------------------------输入发送信息')
browser.switch_to.default_content()
browser.find_element_by_xpath('//footer[@class="jp0"]/div[@class="js-component-button nui-mainBtn nui-btn nui-btn-hasIcon nui-mainBtn-hasIcon  "]').click()
print('------------------------点击发送')